package com.jinzhi.jzweb.controller;


import java.util.*;

import com.jinzhi.jzweb.domain.JazUserCommentDescriptionDO;
import com.jinzhi.jzweb.service.JazUserCommentDescriptionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.JazUserCommentClassifyDO;
import com.jinzhi.jzweb.service.JazUserCommentClassifyService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 评价分类表
 * </pre>
 * <small> 2024-05-16 15:08:53 | Long</small>
 */
@Controller
@RequestMapping("/jazUserCommentClassify")
public class JazUserCommentClassifyController extends BaseController {
	@Autowired
	private JazUserCommentClassifyService jazUserCommentClassifyService;

	@Autowired
	private JazUserCommentDescriptionService jazUserCommentDescriptionService;

	/**
	 * 分页查询评价分类
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	@ResponseBody
	@GetMapping("/list")
	public Result<Page<JazUserCommentClassifyDO>> list(@RequestParam int pageNumber,@RequestParam int pageSize){
        return Result.ok(jazUserCommentClassifyService.getUserCommentClassifyList(pageNumber,pageSize));
	}

	/**
	 * 新增评价类型
	 * @param jazUserCommentClassify
	 * @return
	 */
	@Log(value = "添加评价分类",sysModule = 8,operationType = 1)
	@ResponseBody
	@PostMapping("/save")
	public Result<String> save(@RequestBody JazUserCommentClassifyDO jazUserCommentClassify){
        return jazUserCommentClassifyService.insertUserCommentClassify(jazUserCommentClassify);
	}

	/**
	 * 修改评价类型
	 * @param jazUserCommentClassify
	 * @return
	 */
	@Log(value ="修改评价分类",sysModule = 8,operationType = 3)
	@ResponseBody
	@PostMapping("/update")
	public Result<String>  update(@RequestBody JazUserCommentClassifyDO jazUserCommentClassify){
		return jazUserCommentClassifyService.updateUserCommentClassifyById(jazUserCommentClassify);
	}
	
	@Log(value ="删除评价分类",sysModule = 8,operationType = 2)
	@PostMapping( "/remove")
	@ResponseBody
	public Result<String>  remove( Long id){
		List<JazUserCommentDescriptionDO> userCommentDescriptionDOList = jazUserCommentDescriptionService.selectList(
				new EntityWrapper<JazUserCommentDescriptionDO>().eq("comment_classify_id", id));
		if (userCommentDescriptionDOList.size()>0){
			return Result.fail("评价分类已使用，请先删除评价描述");
		}
		jazUserCommentClassifyService.deleteById(id);
		return Result.ok();
	}

	@Log(value ="修改评价分类启用状态",sysModule = 8,operationType = 3)
	@PostMapping( "/updateUserCommentClassifyStatus")
	@ResponseBody
	public Result<String> updateUserCommentClassifyStatus( @RequestBody JazUserCommentClassifyDO jazUserCommentClassify){
		return jazUserCommentClassifyService.updateUserCommentClassifyStatus(jazUserCommentClassify);
	}
	
	@Log(value ="批量删除评价分类表",sysModule = 8,operationType = 2)
	@PostMapping( "/batchRemove")
	@ResponseBody
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		jazUserCommentClassifyService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
